package com.hqj.demo01;

import java.io.IOException;

/**
 * 类的继承
 */
public class Test01 {

    public static void main(String[] args) {
        Dog d = new Dog();
        d.catchGame();//子类的方法-但是父类的为基础
    }

}

class Animal{
    private String name;
    private String brand;

    public Animal(){}

    public Animal(String name, String brand) {
        this.name = name;
        this.brand = brand;
    }

    public void catchGame(){
        System.out.println("父类的方法catchGame");
    }

    public void run(String name){

    }

    protected void jump(){

    }


    public long eat() throws Exception{
        return -1L;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }
}

class Dog extends Animal{

    private String zcd;

    public Dog(){
        //this.Animal();//构造方法无法继承
        super();//父类的构造方法
    }

    @Override
    public void run(String n) {
        super.run(n);
    }

    @Override  //jdk1.7以前的版本可以不写override
    public void catchGame() {
        //super.catchGame();//以父类为基础
        System.out.println("这里是子类的方法");
    }

    public void test(){
        System.out.println(super.getName());//name是私有化的,getName()是公有化、默认、protected
    }
}

class Cat extends Animal{

    private int livings;

    @Override
    public long eat() throws IOException {
        return 1;
    }

    @Override
    public void jump() {
        super.jump();
    }
}